superstrict

include "tpixmapnormals.bmx"

graphics 800,600,0,0,2

local pixmap:TPixmap = loadpixmap("bitmap.bmp")



local imgNorm:TimageNormals= new TimageNormals

local perfTim1:int = millisecs()
local iters:int = 5
local i:int 
for i=0 until iters
imgNorm.findEdges(pixmap)
next
local perfTim2:int = millisecs()
print "millisecs used finding normals:"+(perfTim2-perfTim1)/iters

while not keyhit(KEY_ESCAPE)
	cls
	
	drawpixmap(pixmap,0,0)
	
	'Draw edges and normals
	local i:int
	local j:int
	local scale# = 2;
	for i=1 until pixmap.width
	for j=1 until pixmap.height
		
		'draw edge pixels. warning: normals are null at non-edge pixels. So, check if pixel
		'exists in edgemap before reading smoothedNormals[]
		if imgNorm.edgemap[i*pixmap.height+j]
			local scx# = i*scale + pixmap.width 
			local scy# = j*scale
			setcolor 255,255,255
			drawrect scx,scy,scale,scale
			local vx# = imgNorm.smoothedNormals[i*pixmap.height+j].x*(scale*2)
			local vy# = imgNorm.smoothedNormals[i*pixmap.height+j].y*(scale*2)

			local pixcenterx# = scx+scale*.5
			local pixcentery# = scy+scale*.5
			setcolor 0,255,0
			drawline pixcenterx,pixcentery, pixcenterx-vx,pixcentery-vy
		endif
	next
	next
	
	flip
wend
